package com.coderman.infosys.auth.app.facadeimpl.authority;

import com.coderman.infosys.auth.app.command.AuthToRoleCmd;
import com.coderman.infosys.auth.domain.repository.AuthorityRepository;
import com.coderman.infosys.plat.auth.common.behavior.AuthorityOpEnum;
import com.coderman.infosys.plat.auth.common.dto.ResultDataDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.coderman.infosys.auth.api.facade.authority.AuthorityFacade;
import com.coderman.infosys.auth.api.dto.authority.request.CreateAuthorityRequestDTO;
import com.coderman.infosys.auth.api.dto.authority.request.UpdateAuthorityRequestDTO;
import com.coderman.infosys.auth.api.dto.authority.AuthorityDTO;
import org.apache.dubbo.config.annotation.Service;
import com.coderman.infosys.auth.domain.factory.AuthorityFactory;
import com.coderman.infosys.auth.app.executor.RoleAuthCmdExe;


/**
 * @Description:权限接口实现类
 * @Author：
 * @CreateTime：2022-01-02 15:27:39
 * @version v1.0
 *
 * 这里由于权限识别为一个聚合根，因此不再需要具体对SystemAuthority,
 * DataAuthority,AdminAuthority做单独的接口实现，不然这样看上去很尴尬，重复而且复杂
 * 所以这里用奥卡姆剃刀原理在接口层剃了一下
 */
@Service
public class AuthorityFacadeImpl   implements AuthorityFacade{

	private  Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private RoleAuthCmdExe roleAuthCmdExe;

    @Override
    public ResultDataDto<AuthorityDTO> authToRole(CreateAuthorityRequestDTO createAuthorityRequestDTO) {
        //todo param Check
        AuthToRoleCmd addRoleAuthCmd = AuthToRoleCmd.buildCmd(createAuthorityRequestDTO);
        return roleAuthCmdExe.exe(AuthorityOpEnum.CREATE_AUTH_TO_ROLE,addRoleAuthCmd);
    }

    @Override
    public ResultDataDto<Boolean> updateAuthToRole(UpdateAuthorityRequestDTO updateAuthorityRequestDTO) {
        //todo param Check
        AuthToRoleCmd addRoleAuthCmd = AuthToRoleCmd.buildCmd(updateAuthorityRequestDTO);
        return roleAuthCmdExe.exe(AuthorityOpEnum.UPDATE_AUTH_TO_ROLE,addRoleAuthCmd);
    }
}